<?
namespace Site\TestModel;

use Site\Model\Users;
use PHPUnit_Framework_TestCase;
 
class UserTest extends PHPUnit_Framework_TestCase
{
    public function testUsersInitialState()
    {
        $users = new Users();
 
        $this->assertNull($users->firstName, '"firstName" should initially be null');
        $this->assertNull($users->id, '"id" should initially be null');
        $this->assertNull($users->lastName, '"firstName" should initially be null');
    }
 
    public function testExchangeArraySetsPropertiesCorrectly()
    {
        
        /*
         *         $this->id     = (isset($data['id'])) ? $data['id'] : null;
        $this->name = (isset($data['name'])) ? $data['name'] : null;
        $this->lastName  = (isset($data['lastName'])) ? $data['lastName'] : null;
        $this->firstName = (isset($data['firstName'])) ? $data['firstName'] : null;
        $this->lastName  = (isset($data['lastName'])) ? $data['lastName'] : null;
    }
         */
        
        
        $users = new Users();
        $data  = array('name' => 'some name',
                       'id'     => 123,
                       'lastName'  => 'some lastName',
                       'firstName'  => 'some firstName'
                        );
 
        $users->exchangeArray($data);
 
        $this->assertSame($data['name'], $users->name, '"name" was not set correctly');
        $this->assertSame($data['id'], $users->id, '"id" was not set correctly');
        $this->assertSame($data['lastName'], $users->lastName, '"lastName" was not set correctly');
        $this->assertSame($data['firstName'], $users->firstName, '"firstName" was not set correctly');
    }
 
    public function testExchangeArraySetsPropertiesToNullIfKeysAreNotPresent()
    {
        $users = new Users();
        $data  = array('name' => 'some name',
                       'id'     => 123,
                       'lastName'  => 'some lastName',
                       'firstName'  => 'some firstName'
                        );
        $users->exchangeArray($data);
        $users->exchangeArray(array());
 
        $this->assertNull($users->name, '"name" should have defaulted to null');
        $this->assertNull($users->id, '"id" should have defaulted to null');
        $this->assertNull($users->firstName, '"firstName" should have defaulted to null');
        $this->assertNull($users->lastName, '"lastName" should have defaulted to null');
    }
}